import { defineStore } from "pinia";
import { ref } from "vue";
import axios from 'axios';
import { nanoid } from 'nanoid'
import LoveTalk from "@/components/LoveTalk.vue";


export const useLoveTalkStore = defineStore('lovetalk', () => {

let talkLists = ref([
    
    { talkList: JSON.parse(localStorage.getItem('talk') as string) || [] }
    
])
    
async function addloveTalk() {
    /* 
        直接进行结构赋值....把发过来的内容内的data对象内的content属性解构出阿里
    */
    let { data: { content } } = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
    let obj = { id: nanoid(), title: content }
    talkLists.value.unshift(obj)
    console.log(talkLists);
    
}

/* 
   添加存储,我们从aixos中获取的图片
*/

    return {addloveTalk,talkLists}
})